<?php
namespace Workerman\Protocols;

Class XmlProtocols{
    public static function input($rec_buffer){
        if(strlen($rec_buffer)<10){
            return 0;
        }
        $total_len = base_convert(substr($rec_buffer,0,10),10,10);
        return $total_len;
    }

    public static function decode($rec_buffer){
        $body = substr($rec_buffer,10);
        return simplexml_load_string($body);
    }

    public static function encode($xml_string){
        $total_length = strlen($xml_string)+10;
        $total_length_str = str_pad($total_length,10,"0",STR_PAD_LEFT);
        return $total_length_str.$xml_string;
    }
}